/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ControlEscolar.DAOs;


import com.ControlEscolar.Beans.Curriculum;
import java.util.ArrayList;


/**
 *
 * @author Listico
 */

public class CurriculumDAO extends AbstractDAO <Curriculum> {

    @Override
    public void add(Curriculum object) throws DAOException {
                String sql = "INSERT INTO curriculum (curriculumName,ID_Major,totalSemester)values(\""
                 + object.getCurriculumName()+"\",\""
                 + object.getID_Major()+"\","
                 + object.getTotalSemester()+");";
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

    @Override
    public int delete(String condition) throws DAOException {
         throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public int update(Curriculum curriculum) throws DAOException {

        String sql="UPDATE curriculum SET curriculumName= \""+curriculum.getCurriculumName()+"\", "+
                "totalSemester= "+curriculum.getTotalSemester()+
                " where ID_Curriculum = "+curriculum.getID_Curriculum();
        try {
            connection.executeUpdate(sql);
        } catch (Exception ex) {
            throw new DAOException();
        }
        return 0;

    }

    @Override
    public ArrayList<Curriculum> query() throws DAOException {
        try {
            String sql = "SELECT * FROM curriculum ";
            return connection.executeQuery(sql, Curriculum.class);

        } catch (Exception ex) {
            throw new DAOException();

        }
    }

    public  Curriculum queryByName(String curriculumName) throws DAOException{
        try {
            String sql = "SELECT * FROM curriculum where curriculumName = \"" + curriculumName+"\"";
            ArrayList<Curriculum> curriculumQuery=connection.executeQuery(sql, Curriculum.class);
            return getSpecificQuery(curriculumQuery);
        } catch (Exception ex) {
            throw new DAOException();

        }
    }

    public ArrayList<Curriculum> queryByID_Major(String ID_Major) throws DAOException {
        try {
            String sql = "SELECT * FROM curriculum where ID_Major =\""+ID_Major+"\"";
            return connection.executeQuery(sql, Curriculum.class);

        } catch (Exception ex) {
            throw new DAOException();

        }
    }



    public Curriculum queryByID(String ID_Curriculum) throws DAOException{
       try {
            String sql = "SELECT * FROM curriculum where ID_Curriculum = \""+ID_Curriculum+"\"";
            ArrayList<Curriculum> curriculumQuery=connection.executeQuery(sql, Curriculum.class);
            return getSpecificQuery(curriculumQuery);
        } catch (Exception ex) {
            throw new DAOException();
        }
    }

}